laravel find

28

// Retrieve a model by its primary key...
$flight = App\Flight::find(1);

// Retrieve the first model matching the query constraints...
$flight = App\Flight::where('active', 1)->first();

// Shorthand for retrieving the first model matching the query constraints...
$flight = App\Flight::firstWhere('active', 1);
$model = App\Flight::where('name', 'Mike')->firstOrFail();
php artisan make:model Flight
// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = App\Models\Flight::updateOrCreate(
    ['departure' => 'Oakland', 'destination' => 'San Diego'],
    ['price' => 99, 'discounted' => 1]
);
public function index()
    {
        $blogs = Blog::find([1, 2, 3]);
        dd($blogs);
    }

Comments

Submit
0 Comments